import React, { Component } from 'react'
// import qs from 'querystring'

export default class Detail extends Component {
    state = {
        contents: [
            {id:'01', content: '我爱你，中国'},
            {id:'02', content: '我爱你，NEC'},
            {id:'03', content: '我爱你，CGQ'}
        ]
    }

    render() {
        // 接受params参数
        // const {id, title} = this.props.match.params | {}
        // const result = this.state.contents.find((detailObj)=>{
        //     return detailObj.id === id
        // }) || {}

        // 接受search参数
        // const {search} = this.props.location
        // const {id, title} = qs.parse(search.slice(1))
        // const result = this.state.contents.find((detailObj)=>{
        //     return detailObj.id === id
        // }) | {}

        // 接受state参数
        const {id, title} = this.props.location.state || {}
        const result = this.state.contents.find((detailObj)=>{
            return detailObj.id === id
        }) || {}
        return (
            <ul>
                <li>ID:{id}</li>
                <li>TITLE:{title}</li>
                <li>CONTENT:{result.content}</li>
            </ul>
        )
    }
}
